#ifndef __HASH_H__
#define __HASH_H__

#include <pthread.h>

#define ENABLE_POINTER_KEY	1

#define MAX_KEY_LEN 128
#define MAX_VALUE_LEN 512

#define MAX_TABLE_SIZE 1024

typedef struct hashnode_s
{
#if ENABLE_POINTER_KEY
    char *key;
    char *value;
#else
    char key[MAX_KEY_LEN];
    char value[MAX_VALUE_LEN];
#endif
    struct hashnode_s *next;
} hashnode_t;

typedef struct hashtable_s
{
    hashnode_t **nodes;
    int max_slots;
    int count;
    pthread_mutex_t lock;
} hashtable_t;

int _hash(char *key, int size);
hashnode_t *_create_node(char *key, char *value);
int init_hashtable(hashtable_t *hash);
void dest_hashtable(hashtable_t *hash);
int put_kv_hashtable(hashtable_t *hash, char *key, char *value);
char *get_kv_hashtable(hashtable_t *hash, char *key);
int count_kv_hashtable(hashtable_t *hash);
int delete_kv_hashtable(hashtable_t *hash, char *key);
int exist_kv_hashtable(hashtable_t *hash, char *key);

#endif // __HASH_H__